package com.wordplat.quickstart.xutils.http;

/**
 * Created by wyouflf on 15/8/4.
 * HTTP谓词枚举
 *
 * @since 2021-05-09
 */
public enum HttpMethod {
    /**
     * GET("GET"),
     * POST("POST"),
     * PUT("PUT"),
     * PATCH("PATCH"),
     * HEAD("HEAD"),
     * MOVE("MOVE"),
     * COPY("COPY"),
     * DELETE("DELETE"),
     * OPTIONS("OPTIONS"),
     * TRACE("TRACE"),
     * CONNECT("CONNECT");
     */
    GET("GET"), POST("POST"), PUT("PUT"), PATCH("PATCH"), HEAD("HEAD"), MOVE("MOVE"),
    COPY("COPY"), DELETE("DELETE"), OPTIONS("OPTIONS"), TRACE("TRACE"), CONNECT("CONNECT");

    private final String value;

    HttpMethod(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return this.value;
    }

    /**
     * permitsRetry
     *
     * @param method
     * @return boolean
     */
    public static boolean permitsRetry(HttpMethod method) {
        return method == GET;
    }

    /**
     * permitsCache
     *
     * @param method
     * @return boolean
     */
    public static boolean permitsCache(HttpMethod method) {
        return method == GET || method == POST;
    }

    /**
     * permitsRequestBody
     *
     * @param method
     * @return boolean
     */
    public static boolean permitsRequestBody(HttpMethod method) {
        return method == null
                || method == POST
                || method == PUT
                || method == PATCH
                || method == DELETE;
    }
}
